// 用户模型
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const User = sequelize.define('User', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  openid: {
    type: DataTypes.STRING(50),
    allowNull: false,
    unique: true,
    comment: '微信openid'
  },
  unionid: {
    type: DataTypes.STRING(50),
    allowNull: true,
    unique: true,
    comment: '微信unionid'
  },
  nickName: {
    type: DataTypes.STRING(50),
    allowNull: true,
    comment: '用户昵称'
  },
  avatarUrl: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: '头像URL'
  },
  gender: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '性别 0:未知 1:男 2:女'
  },
  phone: {
    type: DataTypes.STRING(20),
    allowNull: true,
    comment: '手机号码'
  },
  email: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '邮箱'
  },
  studentId: {
    type: DataTypes.STRING(30),
    allowNull: true,
    comment: '学号'
  },
  school: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '学校'
  },
  major: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '专业'
  },
  studyCountry: {
    type: DataTypes.STRING(50),
    allowNull: true,
    comment: '留学国家'
  },
  studyCity: {
    type: DataTypes.STRING(50),
    allowNull: true,
    comment: '留学城市'
  },
  studyStartDate: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '留学开始时间'
  },
  studyEndDate: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '留学结束时间'
  },
  isMember: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false,
    comment: '是否为会员'
  },
  memberLevel: {
    type: DataTypes.STRING(20),
    allowNull: true,
    comment: '会员等级'
  },
  status: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    comment: '状态 1:正常 2:禁用'
  },
  createdAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'users',
  timestamps: true,
  charset: 'utf8mb4',
  collate: 'utf8mb4_unicode_ci'
});

module.exports = User;